import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-10-11
 * Time: 13:58
 */
public class test2 {
    public int MinimalSizeOfArray(int[] a) {
        // write code here
        int n = a.length;
        if(n==0){
            return 0;
        }
        Map<Integer,Integer> map = new HashMap<>();
        for(int num:a){
            map.put(num,map.getOrDefault(num,0)+1);
        }
        int maxCount = 0;
        for(int count:map.values()){
            if(count>maxCount){
                maxCount = count;
            }
        }
        if(maxCount<=n/2){
            return 0;
        }else{
            return maxCount-(n-maxCount);
        }
    }
}
